package com.zut.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zut.dao.EvaluationDao;
import com.zut.domain.Coach;
import com.zut.domain.Evaluation;
import com.zut.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EvaluationServiceImpl implements EvaluationService {
    @Autowired
    private EvaluationDao evaluationDao;


    public PageInfo<Evaluation> getAll(Integer pageNum, Integer pageSize) {
        List<Evaluation> list;
        PageHelper.startPage(pageNum, pageSize);
        list = evaluationDao.getAll();
        return new PageInfo<>(list);
    }

    public boolean insert(Evaluation evaluation) {
        return evaluationDao.insert(evaluation) > 0;
    }

    public boolean deleteById(String userId, String evaluationId) {
        return evaluationDao.deleteById(userId, evaluationId) > 0;
    }

    public boolean update(Evaluation evaluation) {
        return evaluationDao.update(evaluation) > 0;
    }

    public PageInfo<Evaluation> getById(Integer pageNum, Integer pageSize, String id) {
        List<Evaluation> list;
        PageHelper.startPage(pageNum, pageSize);
        list = evaluationDao.getById(id);
        return new PageInfo<>(list);
    }

    public PageInfo<Map<String ,String>> getAvgGrade(Integer pageNum, Integer pageSize) {
            List<Map<String,String>> list;
            PageHelper.startPage(pageNum, pageSize);
            list = evaluationDao.getAvgGrade();
            return new PageInfo<>(list);
        }
    }

